<template>
  <div class="app-container">
    <div id="main" style="width: 2000px; height: 1000px;"></div>
  </div>
</template>

<script>
import { chartList } from "@/api/gxs/activity";
import * as echarts from 'echarts';
import item from "../../../layout/components/Sidebar/Item";

export default {
  name: "ActivityChart",
  mounted() {
    this.initChart();
  },
  data() {
    return {
      // 活动图表表格数据
      activityChartList: [],
      convertedData:[],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gxsPendTitle: null,
        parentId: null,
        deptId: null,
        gxsTypeId: "",
        gxsPendState: "",
        gxsPendEventDate: null,
        gxsLimit: null,
        gxsParticipant: null,
        gxsScore: null
      },
    };
  },
  created() {
    this.getList();
  },
  watch:{
    convertedData(newValue){
      this.initChart();
    }
  },
  methods: {
    getList() {
      chartList(this.queryParams).then(response => {
        this.activityChartList = response.rows;

        console.log(this.activityChartList);
        this.convertedData = this.activityChartList.map(item => ({ value: item.num, name: item.type }));
        console.log(this.convertedData);
      });

    },
    initChart() {
      var chartDom = document.getElementById('main');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '活动类型比例',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: this.convertedData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }
};
</script>
